# 管理员登录界面
from selenium.webdriver.common.by import By
from base.page_base import BasePage


class AdminLogin(BasePage):
    """管理员登录页面"""

    # 元素定位
    __username = By.ID, 'username' # 用户名文本
    __password = By.ID, 'password'  # 密码文本
    __verifycode = By.ID, 'valicode'  # 验证码文本
    __login_btn = By.CLASS_NAME, 'login-button'  # 登录按钮
    __assert_success_text = By.XPATH, '//div[text()="欢迎光临,"]' # 登录成功断言文本
    __assert_fail_text = By.ID, 'errorMessage' # 登录失败断言文本

    def open_url(self):
        self.driver.get('http://121.43.169.97:8082/')

    def input_username(self, username):  # 输入用户名
        self.base_input(self.__username, username)

    def input_password(self, password):  # 输入密码
        self.base_input(self.__password, password)

    def input_verifycode(self, verifycode='8888'):  # 输入验证码
        self.base_input(self.__verifycode, verifycode)

    def click_login_btn(self):  # 点击登录按钮
        self.base_click(self.__login_btn)

    def assert_login_success(self):  # 断言登录成功
        return self.base_get_text(self.__assert_success_text)

    def assert_login_fail(self):  # 断言登录失败
        return self.base_get_text(self.__assert_fail_text)

    def admin_login_operation(self, username, password, verifycode):
        self.input_username(username)  # 输入用户名
        self.input_password(password)  # 输入密码
        self.input_verifycode(verifycode)  # 输入验证码
        self.click_login_btn()  # 点击登录按钮
